package com.lmonkey.servlet.cate;

import com.lmonkey.dao.Basedao;
import com.lmonkey.shop.CATEGORY;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/admin/admin_docateupdate")
public class DoCateUpdate extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //获取参数
        int fid = Integer.parseInt(request.getParameter("parentid"));

        int id = Integer.parseInt(request.getParameter("id"));
        String name = request.getParameter("classname");

        CATEGORY cate = new CATEGORY(id,name,fid);
        //连接数据库
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        try{
            String sql = "update lmonkey_category set cate_name = ? ,cate_parent_id = ? where cate_id = ?";
            ps = conn.prepareStatement(sql);
            ps.setObject(1,cate.getCate_name());
            ps.setInt(2,cate.getCate_parent_id());
            ps.setInt(3,cate.getCate_id());
            ps.executeUpdate();
        }catch (SQLException e)
        {
            e.printStackTrace();
        }

        response.sendRedirect("admin_cateselect");
    }
}
